library(readr)
library(missRanger)
library(here) #use with an R project

set.seed(123L)

#Bring in dataframe
master_dataset_for_RF <- read_csv("RIO_replication/master_dataset.csv")

#Use Random Forest for missingness on controls
rf_df <- missRanger(master_dataset_for_RF, pmm.k = 3, num.trees = 100)

#Export back to Stata for analysis
write.csv(rf_df, here("RIO_replication", "master_dataset_RF_MI.csv"), row.names = FALSE)
